<?php
require_once("qqcon.php");
header("Content-Type:text/html; charset=utf-8");

if(isset($_COOKIE["qq"])){
    $qqid=$_COOKIE["qq"];
}else{
$res=mysql_query("select clicks from qqslink where state=1");
$akarr=array();
while($row=mysql_fetch_row($res)){   //获取点击数
    $akarr[]=$row[0];
}
$minsk=min($akarr);     //取得最小点击数
$res2=mysql_query("select id,qq from qqslink where clicks=$minsk and state=1 limit 1");  //取得最小点击数的id和qq
$msqq=mysql_result($res2,0,1);
$msid=mysql_result($res2,0,0);
if(mysql_query("update qqslink set clicks=clicks+1 where id=$msid and state=1")){   //点击数自加1
    $qqid=$msqq;
}
setcookie("qq","$qqid",time()+60);
}

header("location:http://wpa.qq.com/msgrd?v=3&uin=$qqid&site=qq&menu=yes");


?>